@extends('manage.layout')

@section('content')
<body class="hold-transition skin-blue sidebar-mini">
  <!-- Content Wrapper. Contains page content -->
  <div class="content">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        修改管理员信息&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/system/admin" class="btn btn-primary">返回</a>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li><a href="#">admin</a></li>
        <li class="active">Update admin</li>
      </ol>
    </section>
    <!-- Main content -->
    <section class="content">
      <div class="row">
        <!-- left column -->
        <div class="col-md-12">
          <!-- general form elements -->
          <div class="box box-primary">
            <div class="box-header with-border">
              <h3 class="box-title"></h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form  action="{{ url('system/admin/updateAdmin') }}"  role="form" method="post">
              <input type="hidden" name="id" value="{{$oneInfo->id}}" />
              {{ csrf_field() }}
              <div class="box-body" style="width: 50%;">
                <div class="form-group">
                  <label for="exampleInputPassword1">角色名称</label>
                  <select name="role_id" class="form-control">
                    @foreach($role as $value)
                      <option value="{{ $value['id'] }}" @if($value['id'] == $oneInfo->role_id)selected="selected"@endif>{{ $value['name'] }}</option>
                    @endforeach
                  </select>
                </div>
                <div class="form-group">
                  <label for="exampleInputEmail1">管理员名称</label>
                  <input type="text" name="username" class="form-control" value="{{$oneInfo->username}}" placeholder="admin username" required="required">
                </div>
                <div class="form-group">
                  <label for="exampleInputEmail1">权重</label>
                  <input type="number" name="rank" class="form-control" value="{{$oneInfo->rank or 0}}" placeholder="admin rank" required="required">
                </div>
                <div class="form-group">
                  <label for="exampleInputEmail1">新密码</label>
                  <input type="password" name="password" class="form-control"  placeholder="admin password">
                </div>
                <div class="form-group">
                  <label for="exampleInputEmail1">确认密码</label>
                  <input type="password" name="password_confirmation" class="form-control" placeholder="Confirm Password">
                </div>


               
              </div>
              <!-- /.box-body -->

              <div class="box-footer">
                <button type="submit" class="btn btn-primary">提交</button>
              </div>
            </form>
          </div>
          <!-- /.box -->

        </div>
       
        <!--/.col (right) -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
@stop
  @section('script')
    <script>
      $(function(){
        //提交表单
        $("form").submit(function(event) {
          event.preventDefault();
          var url = $(this).attr("action");
          $.ajaxSetup({
            headers: {
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
          });
          $.ajax({
            url: url,
            type: "POST",
            data: $("form").serialize(),
            dataType: "json",
            success: function(data) {
              console.log(data);
              if(data.error == 0) {
                window.location.href = window.location.href;
                layer.msg(data.msg,{icon: 1});
              }
              else {
                layer.msg(data.msg,{icon: 2});
              }
            },
            error:function(){
              layer.msg('ERROR',{icon: 2});
            }
          });
        });
      });

    </script>
@stop